package cocurrency.cyclicbarrier;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

/**
 * Created by luzl on 4/6/2017.
 */
public class RunnerThread extends Thread {

    private String name;
    private CyclicBarrier cyclicBarrier;

    public RunnerThread(String name, CyclicBarrier cyclicBarrier){
        this.name=name;
        this.cyclicBarrier=cyclicBarrier;
    }

    public void run(){
        System.out.println(this.name+" waiting to start");
        try {
            cyclicBarrier.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (BrokenBarrierException e) {
            e.printStackTrace();
        }
        System.out.println(this.name+" executing task");
    }
}
